#include "Project_main2.h"
#include "Project_main3.h"
#include "Project_main4.h"

extern unsigned char IP_Hao;
uint8_t max_Th2 = 0;
uint8_t max_Tl2 = 0;
extern uint8_t max_num2;

void get_temp2(void)
{
	float temp;
    uint8_t temp_buff[max_Th2][max_Tl2][2];
    for (int i = 0; i < max_Th2; i++) {
        for (int j = 0; j < max_Tl2; j++) {
            for (int k = 0; k < 2; k++) {
                temp_buff[i][j][k] = 0xff;
            }
        }
    }

    GXHT2W_Search_Rom();
	if(max_num2 != GXHT2W_SensorNum)
	{
		get_Search2(&max_num2);
	}

    for (int num = 0; num < GXHT2W_SensorNum; num++) {
		GXHT2W_change_Temp(ucGXHT2WId[num]);
    }
	OneWire2_UP_1;
	delay_ms(800);
	OneWire2_UP_0;
	//----------------------------------------------------------
	    for (int num = 0; num < GXHT2W_SensorNum; num++) {

//				readT = 0;
				temp = GXHT2W_Read_Temp(ucGXHT2WId[num], &GXHT2W_Th, &GXHT2W_Tl);
				temp_buff[GXHT2W_Th - 1][GXHT2W_Tl - 1][0] = temp;
				temp_buff[GXHT2W_Th - 1][GXHT2W_Tl - 1][1] = temp * 100 - (int)temp * 100;
				OLED_ShowNum(2, 1, temp, 3);
				OLED_ShowChar(2, 4, '.');
				OLED_ShowNum(2, 5, temp * 100 - (int)temp * 100, 2);
				OLED_ShowNum(3, 1, GXHT2W_Th, 2);
				OLED_ShowNum(3, 7, GXHT2W_Tl, 2);
				OLED_ShowNum(4, 1, max_Th2, 5);
				OLED_ShowNum(4, 7, max_Tl2, 5);
//				delay_ms(2);
		
    }
    for (int i = 0; i < max_Th2; i++) {
        for (int j = 0; j < max_Tl2; j++) {
            for (int k = 0; k < 2; k++) {
                UART1Send(temp_buff[i][j][k]);
            }
        }
    }
}

void get_Search2(uint8_t *xh)
{

	//----------------------------------------------------------

			    GXHT2W_Search_Rom();
	if(GXHT2W_SensorNum != 0)
	{
			    for (int num = 0; num < GXHT2W_SensorNum; num++) {
				GXHT2W_Read_Temp(ucGXHT2WId[num], &GXHT2W_Th, &GXHT2W_Tl);
				OLED_ShowNum(2, 1, GXHT2W_Th, 2);
				OLED_ShowNum(2, 4, GXHT2W_Tl, 2);
				if (GXHT2W_Th > max_Th2) {
					max_Th2 = GXHT2W_Th;
				}
		
				if (GXHT2W_Tl > max_Tl2) {
					max_Tl2 = GXHT2W_Tl;
				}
		
    }
	}

	//------------------------------------------------------------	


//			    GXHT3W_Search_Rom();
//	if(GXHT3W_SensorNum != 0)
//	{
//			    for (int num = 0; num < GXHT3W_SensorNum; num++) {
//				GXHT3W_Read_Temp(ucGXHT3WId[num], &GXHT3W_Th, &GXHT3W_Tl);
//				OLED_ShowNum(2, 7, GXHT3W_Th, 2);
//				OLED_ShowNum(2, 10, GXHT3W_Tl, 2);
//				if (GXHT3W_Th > max_Th2) {
//					max_Th2 = GXHT3W_Th;
//				}
//		
//				if (GXHT3W_Tl > max_Tl2) {
//					max_Tl2 = GXHT3W_Tl;
//				}
//		
//    }
//	}


////		//------------------------------------------------------------	

//				GXHT4W_Search_Rom();	
//		if(GXHT4W_SensorNum != 0)
//		{
//					    for (int num = 0; num < GXHT4W_SensorNum; num++) {
//				 GXHT4W_Read_Temp(ucGXHT4WId[num], &GXHT4W_Th, &GXHT4W_Tl);
//				OLED_ShowNum(3, 1, GXHT4W_Th, 2);
//				OLED_ShowNum(3, 4, GXHT4W_Tl, 2);
//				if (GXHT4W_Th > max_Th2) {
//					max_Th2 = GXHT4W_Th;
//				}
//		
//				if (GXHT4W_Tl > max_Tl2) {
//					max_Tl2 = GXHT4W_Tl;
//				}	
//    }
//		}

	//------------------------------------------------------------
	OLED_ShowNum(4, 1, max_Th2, 2);
	OLED_ShowNum(4, 4, max_Tl2, 2);
	*xh = GXHT2W_SensorNum + GXHT3W_SensorNum + GXHT4W_SensorNum;
	OLED_ShowNum(1, 1, *xh, 3);
}


